package com.nowcoder.Offer.String;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class ReverseSentence {
    public String ReverseSentence(String str) {
        if(str.trim().equals("")){
            return str;
        }
        String[] strs = str.trim().split(" ");

        ArrayList<String> list = new ArrayList<>(Arrays.asList(strs));

        Collections.reverse(list);

        StringBuilder strb = new StringBuilder();

        list.forEach(e -> strb.append(e+" "));

        strb.deleteCharAt(strb.length()-1);

        return strb.toString();
    }

    @Test
    public void test(){
        String str = " ";
        System.out.println(ReverseSentence(str) + 1);
    }
}
